﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using Tesla.Service.DataContracts;
using System.Web.Caching;
using System.Web.SessionState;
using System.Configuration;


namespace Tesla.Web
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {
            
        }

        protected void Session_Start(object sender, EventArgs e)
        {

        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {
            //if (Server.GetLastError() != null && Server.GetLastError() is HttpRequestValidationException)
            //{
            //    Session["ErrorDetail"] = "HTTP Request validation exception occurred!";
            //    Server.ClearError();  
            //    Response.Redirect("~/Pages/ErrorPage/GenericErrorPage.aspx");
            //}
        }

        protected void Session_End(object sender, EventArgs e)
        {
            Session.Abandon();
        }

        protected void Application_End(object sender, EventArgs e)
        {
            string currentKey= "";
            System.Collections.IDictionaryEnumerator cacheContents =  System.Web.HttpContext.Current.Cache.GetEnumerator ();
            
            while (cacheContents.MoveNext()) 
            {
            currentKey = cacheContents.Key.ToString();
            System.Web.HttpContext.Current.Cache.Remove(currentKey);
            }
        }
    }
}